﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KPIS.GERP.WEB.GIMS.Controllers
{
    public class MasPurchaseTypeController : Controller
    {
        //
        // GET: /MasPurchaseType/

        public ActionResult Index()
        {
            var service = new IcmMasterService.IcmMasterServiceClient();
            var model = service.SelectPurchaseType(new Models.ICM.MasPurchaseType { RecordStatus = "U" }, null).ToList();
            return View(model);
        }

        public ActionResult Edit(int Id)
        {
            var service = new IcmMasterService.IcmMasterServiceClient();
            var model = service.SelectPurchaseType(new Models.ICM.MasPurchaseType { PcTypeId = Id }, null).FirstOrDefault();

            return View(model);
        }

        [HttpPost]
        public ActionResult Edit(int Id, Models.ICM.MasPurchaseType model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var service = new IcmMasterService.IcmMasterServiceClient();
                    service.UpdatePurchaseType(model, Class.GimsMembership.CurrentEmpId);
                    return RedirectToAction("Details", new { Id = model.PcTypeId });
                }

                return View(model);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Empty", ex.Message);
                return View(model);
            }
        }

        public ActionResult Details(int id)
        {
            var service = new IcmMasterService.IcmMasterServiceClient();
            var model = service.SelectPurchaseType(new Models.ICM.MasPurchaseType { PcTypeId = id }, null).FirstOrDefault();
            return View(model);
        }
    }
}
